#include <sys/types.h>
#include <dirent.h>
#include "../ourhdr.h"

/***
 * 列出目录下的文件及子目录名
 **/

int main(int argc, char* argv[])
{
    DIR *dp;
    struct dirent *dirp;
    if(argc !=2)
    {
        err_quit("a single argument (the directory name) is required");    
    }

    if((dp = opendir(argv[1])) == NULL) 
    {
        err_sys("can't open %s", argv[1]);
    }

    while( (dirp=readdir(dp))!=NULL)
    {
        printf("%s\n", dirp->d_name);
    }
    
    closedir(dp);
    exit(0);
}